<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .swicth-box {
            width: 100px;
            height: 50px;
            border-radius: 50px;
            background-color: #999;
            position: relative;
        }

        .swicth-span {
            transition: all 0.7s;
            display: inline-block;
            width: 45px;
            height: 45px;
            border-radius: 50%;
            background-color: white;
            position: absolute;
            top: 2.5px;
            left: 2.5px;
        }
    </style>
</head>

<body>
    <div id="app">
        <swicth v-model="flog"></swicth>
    </div>
</body>
<script src="vue.js"></script>
<script type="text/html" id="swicth">
    <div 
    class="swicth-box"
    @click = "swicthClick"
    :style="swboxStyle"
    >
        <span class="swicth-span" :style="swStyle"></span>
    </div>
</script>
<script>

    Vue.component("swicth", {
        template: "#swicth",
        props: {
            value: {
                type: Boolean,
                default: false
            }
        },
        methods: {
            swicthClick() {
                this.$emit("input", !this.value)
            },
        },
        computed: {
            swStyle() {
                if (this.value) {
                    return {
                        left:"52px"
                    }
                }else{
                    return {
                        left:"2.5px"
                    }
                }
            },
            swboxStyle(){
                if (this.value) {
                    return {
                        "background-color":"#4da2fd"
                    }
                }else{
                    return {
                        "background-color":"#999"
                    }
                }
            }
        }
    })

    new Vue({
        el: "#app",
        data: {
            flog: false
        }
    })
</script>

</html>